/**
 * 
 */
package cn.biplam.front.template.control.pop;

import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.data.common.CaptionComp;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlText;
import cn.biplam.front.html.base.Html;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Float_Type;
import cn.biplam.front.html.base.Const.Repeat_Type;
import cn.biplam.front.html.base.Const.Window_Event;
import cn.biplam.front.template.Template;
import cn.biplam.front.template.base.ButtonImageSmall;
import cn.biplam.front.template.control.pop.PopLevel.Frame_Layer;

/**
 * 带有标题栏和关闭按钮的框
 * @author 	WangSong
 * @create 	2009-4-15 上午10:42:10
 * @version 1.0
 */
public class Frame implements Template{
	
	private UserInfo mUser;
	
	private HtmlDiv frame;
	private HtmlDiv content;
	private HtmlWindow button;
	private String ID;
	private String sHomeUrl;
	private String sTitle;
	
	/**
	 * 功能：构造方法
	 * @param ID		Frame的页面ID(不能为空)
	 * @param sHomeUrl	主页Url
	 * @param sTitle	Frame的标题
	 * @throws ErrorMessage 
	 */
	public Frame(String ID,String sHomeUrl,UserInfo mUser,String sTitle) throws ErrorMessage{
		if(ID==null || ""==ID) throw new ErrorMessage("Frame控件ID不能为空!");
		this.ID = ID;
		this.sHomeUrl=sHomeUrl;
		this.sTitle=sTitle;
		this.mUser=mUser;
		this.frame=new HtmlDiv(ID,"fd");
		this._init();
	}
	
	private void _init() throws ErrorMessage{
		this.setSize(300,200);
		
		/**创建标题*/
		HtmlDiv title=new HtmlDiv(null,"ft");
		frame.put(title);
		title.setBackGroundRepeat(Repeat_Type.Repeat_X);
		title.setBackGroundImage(this.sHomeUrl+"/images/title_bg.gif");
		//设置文字
		HtmlText text=new HtmlText(this.ID+"t","fst",this.sTitle);
		title.put(text);
		text.setFloat(Float_Type.Left);
		text.setMarginLeft("5");
		//设置图片
		this.button = new ButtonImageSmall(this.ID+"i",sHomeUrl+"/images/wcloseu.gif",sHomeUrl+"/images/wclose.gif").get();
		title.put(button);
		button.setFloat(Float_Type.Right);
		button.setTitle(CaptionComp.get(mUser,"33"));//关闭
		
		/**创建内容*/
		this.content=new HtmlDiv(this.ID+"c","fc");
		frame.put(this.content);

	}
	
	/**
	 * 功能：向Frame正文区域放入Html对象
	 * @param html
	 * @throws ErrorMessage
	 */
	public void put(Html html) throws ErrorMessage{
		this.content.put(html);
	}
	
	/**
	 * 功能：向Frame父容器放入Html对象
	 * @param html
	 * @throws ErrorMessage
	 */
	public void putFrame(Html html) throws ErrorMessage{
		this.frame.put(html);
	}
	
	/**
	 * 功能：设置frame正文区域的宽度和高度(标题高度是20px)
	 * @param width
	 * @param height
	 * @throws ErrorMessage
	 */
	public void setSize(int width,int height) throws ErrorMessage{
		this.frame.setStyleWidth(Integer.toString(width));
		this.frame.setStyleHeight(Integer.toString(height+20));
	}
	
	/**
	 * 功能：设置Frame的布局层次
	 * @param layer {@link Layer_Index}
	 * @throws ErrorMessage
	 */
	public void setLayerIndex(Frame_Layer layer) throws ErrorMessage{
		this.frame.setZIndex(layer.toString());
	}
	
	/**
	 * 功能：绑定Frame的关闭按钮事件
	 * @param sScript			事件执行的js脚本
	 * @throws ErrorMessage
	 */
	public void bindClose(String sScript) throws ErrorMessage{
		this.button.bind(Window_Event.OnClick, sScript);
	}
	
	/**
	 * 功能：返回设置好的HtmlWindow对象
	 * @return
	 */
	public HtmlWindow get(){
		return this.frame;
	}

}
